package com.bing.controller.admin;

import com.bing.bean.ResultMsg;
import com.bing.entity.Resource;
import com.bing.mvc.resolver.JsonObejct;
import com.bing.services.RoleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("role")
public class RoleController {
    public static final Logger LOGGER = LoggerFactory.getLogger(RoleController.class);
    @Autowired
    private RoleService roleService;


    @RequestMapping(value = {"/resource/root.json", "/resource/root.xml"},method = RequestMethod.POST)
    @ResponseBody
    public List<Resource> root() {
        LOGGER.info("get resourceRoot");
        return roleService.getRoot();
    }

    @RequestMapping(value = "/resource/edit",method = RequestMethod.POST)
    @ResponseBody
    public ResultMsg edit(@JsonObejct Resource resource){
        LOGGER.info("edit resource:{}",resource);
        roleService.addOrUpdate(resource);
        return ResultMsg.sucess();
    }
}
